﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

namespace ProveedorVuelosWCF.Persistencia
{
    public class CiudadDAO
    {
        String strCnx = "data source=64.49.237.194;initial catalog=BDreserva;persist security info=True;user id=psdesa;password=PSdesa2014";

        public bool ExisteCiudad(String pStrIdCiudad){
            bool bolExiste = false;
            using (SqlConnection objSqlConnection = new SqlConnection(strCnx))
            {
                using (SqlCommand objSqlCommand = new SqlCommand())
                {
                    objSqlCommand.CommandText = "SELECT COUNT(*) AS CANTIDAD FROM TB_CIUDAD WHERE CIU_ID=@ID_CIUDAD";

                    objSqlCommand.Parameters.Add(new SqlParameter("@ID_CIUDAD", pStrIdCiudad));
                    objSqlConnection.Open();
                    objSqlCommand.Connection = objSqlConnection;

                    using (SqlDataReader objSqlDataReader = objSqlCommand.ExecuteReader()){
                        if (objSqlDataReader.Read()) {
                            if (int.Parse(objSqlDataReader["CANTIDAD"].ToString()) > 0) {
                                bolExiste = true;
                            }
                        }
                    }
                }
            }
            return bolExiste;
        }
    }
}